<?php
namespace Api\Controller\V2;
use Think\Controller;
/**
* @name Lukeyan
* @abstract 申明变量/类/方法
* @access 指明这个变量、类、函数/方法的存取权限
* @author 函数作者的名字和邮箱地址
* @category  组织packages
* @copyright 指明版权信息
* @const 指明常量
* @deprecate 指明不推荐或者是废弃的信息MyEclipse编码设置
* @example 示例
* @exclude 指明当前的注释将不进行分析，不出现在文挡中
* @final 指明这是一个最终的类、方法、属性，禁止派生、修改。
* @global 指明在此函数中引用的全局变量get_share
* @include 指明包含的文件的信息
* @link 定义在线连接
* @module 定义归属的模块信息
* @modulegroup 定义归属的模块组
* @package 定义归属的包的信息
* @param 定义函数或者方法的参数信息
* @return 定义函数或者方法的返回信息
* @see 定义需要参考的函数、变量，并加入相应的超级连接。
* @since 指明该api函数或者方法是从哪个版本开始引入的
* @static 指明变量、类、函数是静态的。
* @throws 指明此函数可能抛出的错误异常,极其发生的情况
* @todo 指明应该改进或没有实现的地方
* @var 定义说明变量/属性。
* @version 定义版本信息
*/

/*
 * 众筹功能页面
 */
class FoundingController extends CommonController {
    public function index(){
        header("Content-type:text/html;charset=utf8;");
        echo "众测天下";
    }
    
    
    /*
     * 众筹项目列表功能
     * 
     * @acccess public
     * @param type 列表的规则（ 默认为0，1 是众筹中，2 是抽样中，3 是有结果了）
     * @return 众筹项目列表的数组
     */
    public function get_all() {
        $type = trim(I('get.type'));
        $mid = trim(I('get.mid'));
        $password = trim(I('get.password'));
        $mtype = trim(I('get.mtype'));
        $pagecount = I('get.pagecount');
        $keywords = trim(I('get.keywords'));
        
        /*
         * 过滤掉未支付的订单
         */
        
        
        if(empty($pagecount))
        {
            $pagecount=0;
        }
        
        $startpoint = $pagecount*10;
        
        
        if(!empty($type))
        {
            $map['state']=$type;
        }
        
        if($mtype>0)
        {
//            会员中心的地方使用，0 为默认值，1 是我发起的，2 是我参与的，3 是我关注的，只有在mid 大于0的情况下有用
            
            switch ($mtype) {
                case 1:
                    $map['mid']=$mid;
                    break;
                case 2:
//                    我参与的项目的算法
                    /*
                     * 从投钱成功的表中取得数据
                     * fd_fundings_sponsor
                     * 
                     */
                    $DB_sponsor = M('fundings_sponsor');
                    $map_sponsor['mid']=$mid;
                    $map_sponsor['status']=1;
                    
                    $res_sponsor = $DB_sponsor->where($map_sponsor)->order("state,ctime")->select();
//                    echo $DB_sponsor->getLastSql();
                    if(!empty($res_sponsor))
                    {
                        foreach ($res_sponsor as $k => $v) {
                           $id_arr[]=$v['fid']; 
                        }
                    }
                    $map['id']=array('in',$id_arr);

                    break;
                    
                case 3:
                    $map['mid']=$mid;
                    break;

                default:
                    $map['mid']=$mid;
                    break;
            }
            
        }
        
        if(!empty($keywords))
        {
            $map['pjname']=array("like","$keywords");
        }
        
        $DB = M('fundings');
        $res = $DB->where($map)->order('id DESC')->limit($startpoint,10)->select();
        if(!empty($res))
        {
            foreach ($res as $key => $value) {
                $res[$key]['packagename']=  $this->get_packagename_by_id($value['packageid']);
                $res[$key]['institution']= $this->get_institutionname_by_id($value['institutionid']);
                $res[$key]['testing_date']= date("Y-m-d",$value['ctime']);
                //目标金额的计算
                $res[$key]['emoney'] = $value['emoney']+$value['samnum']*$value['smoney'];
                //发起人信息
                $res[$key]['username']=  $this->_get_member_nickname($value['mid']);
                $res[$key]['avatar']=  $this->_get_one_avatar($value['mid']);
                
                //已筹金额、人数、目标金额
                $res[$key]['emoney'] = ($value['emoney']+$value['smoney']*$value['samnum']);
                $res[$key]['sponsors_count']=  $this->get_one_sponsor_count($value['id']);
                
                if(empty($value['thumb']))
                {
                    $res[$key]['thumb']=C("product_domain")."/Public/assets/img/bg_fix.png";
                }
                
                $res[$key]['testing_result']=  $this->_get_testing_report_short_analyze($value['testreportid']);
            }
        }        
        
        $page_res=array();
        foreach ($page_res as $key => $value) {
            if(($key>=$pagecount*10)&&($key<($pagecount*20+20)))
            {
                array_push($page_res, $value);
            }
        }

        
        $this->json_output($res);
   
    }
    
    public function get_latest() {
        $type = 3;
        $mid = trim(I('get.mid'));
        $password = trim(I('get.password'));
        
        
        if(!empty($type))
        {
            $map['state']=$type;
        }

        
        
        $DB = M('fundings');
//        $map
        $res = $DB->where($map)->order('id DESC')->limit(10)->select();
        if(!empty($res))
        {
            foreach ($res as $key => $value) {
                $res[$key]['packagename']=$this->get_packagename_by_id($value['packageid']);
                $res[$key]['institution']=$this->get_institutionname_by_id($value['institutionid']);
                $res[$key]['emoney']=($value['emoney']+$value['smoney']*$value['samnum']);
                
                if(empty($value['thumb']))
                {
                    $res[$key]['thumb']="http://test.mdjkj.com/foodcase/Public/assets/img/bg_fix.png";
                }
                
            }
        }        
        
        $this->json_output($res);
   
    }
    
    /*
     * 获取单个众筹项目详情
     */
    public function get_one() {
        $id = I('get.id');
        $mid = I("get.mid");
        
        $DB = M('fundings');
//        $map
        $res = $DB->find($id);
         
        $res['packagename']=$this->get_packagename_by_id($res['packageid']);
        $res['institution']=$this->get_institutionname_by_id($res['institutionid']);
        //判断用户是否关注了项目
        $res['ifcollection']=  $this->chk_if_member_follow_founding($mid, $id);
        if(empty($res['thumb']))
        {
            $res['thumb']=C('product_domain')."/Public/assets/img/bg_fix.png";
            
        }
//        $res['mid']=  $this->get_username_by_id($res['mid']);
        $res['username']=  $this->get_username_by_id($res['mid']); //发起人
        $res['avatar']=  $this->_get_one_avatar($res['mid']);
        $res['category']=  $this->_get_name_by_sortid($res['first_categoryid']);
        
        //项目的总需要金额
        $res['emoney']=($res['emoney']+$res['smoney']*$res['samnum']);

        if(empty($res['testreport_detail'])){

            unset($res['testreport_detail']);
        }else{

            $res['testreport_detail'] = explode(',',$res['testreport_detail']);
        }      

        $fundings_image = M('fundings_image');

        foreach ($res['testreport_detail'] as $k => $v) {
            # code...
            $testreport_images = $fundings_image->where(array('id' => $v))->find();

            if(!empty($testreport_images)){

                $res['testreport_jpg'][] = $testreport_images;
            }else{

                $res['testreport_jpg'] = array();
            }
        }
        
        // $testreport = $this->get_testreport_by_id($res['testreportid']);
        // if(empty($testreport))
        // {
        //     $res['testreport'] = array();
        //     $res['testreport_jpg'] = array();
        // }
        // else
        // {   
        //     $res['testreport'] = array('0' => array('id' => $testreport['id'],'img_url' =>$testreport['download']));
        //     $res['testreport_jpg'] = array('0' => array('id' => $testreport['id'],'img_url' =>$testreport['download_jpg']));
        // }
        
        
        //用户的样品图
        if(!empty($res['sampleid']))
        {
            $sampleids = explode(",", $res['sampleid']);
            $sample_result = array();
            foreach ($sampleids as $key => $value) {
                $sample_result[]=  $this->get_sample_img_by_id($value);
            } 
            
            $res['samples']=$sample_result;
        }
        else
        {
            $res['samples']=array();
        }
            
        
        //详情头部图片
        $res['detail_thumb_lists']=  $this->get_one_thumb_list($res['detail_thumb']);
        
        
        
        
        
        
//        支持者
        $res['latest_six_sponsors']=  $this->get_one_lastest_six_sponsors($id);
        $res['hot_sponsors']=  $this->get_one_most_sponsors($id);
        $res['sponsors_count']=  $this->get_one_sponsor_count($id);
        //热门评论
        $res['comment_count']=  $this->get_one_comments_count($id);
        $res['hot_comments']=  $this->get_one_hot_comments($id);
        
        if(!empty($res['detail_thumb'])){

            $res['thumb_list'] = $this->get_one_thumb_list($res['detail_thumb']);
        }else{

            $res['thumb_list'] = array();
        }
        
        //项目的顶部列表图片展示
        $this->json_output($res);
    }
    
    
    
    
    
    
    /*
     * 获取单个众筹的产品内容
     */
    public function get_one_packages() {
       $id = I('get.id');
        $DB = M('fundings');
        $finfo = $DB->find($id); 
        $packageids = explode(",", $finfo['packageid']);
        foreach ($packageids as $key => $value) {
            $res[]=  $this->get_package_by_id($value);
        }
        $this->json_output($res);
        
    }
    
    /*
     * 获取单个众筹的机构详情
     */
    public function get_one_institution() {
        $id = I('get.id');
        $DB = M('fundings');
//        $map
        $finfo = $DB->find($id);
        // exit("ddd");
        $res = $this->get_institution_by_id($finfo['institutionid']);
        if(!empty($res)){
            $this->json_output($res);
        }
        else
        {
            $no_msg = "";
          $this->json_output($no_msg);      

        }
        
    }
    
    
    /*
     * 获取单个项目的参与者列表
     */
    public function get_one_sponsor() {
        $id = I('get.id');
        $pagecount = I("get.pagecount");
        
        if(empty($pagecount))
        {
            $pagecount=0;
        }
        
        $startpoint = $pagecount*10;
        
        $DB = M('fundings_sponsor');
        $map['fid']=$id;
        $map['status']=1;
        $res = $DB->where($map)->join("LEFT JOIN `fd_members` ON `fd_members`.id= `fd_fundings_sponsor`.mid")->order('`fd_fundings_sponsor`.paytime DESC')->limit($startpoint,10)->select();
        
        foreach ($res as $key => $value) {
            $res[$key]['sponsor_name']=  $this->get_username_by_id($value['mid']);
            $res[$key]['mid']=  $this->get_username_by_id($value['mid']);

            
        }

        $this->json_output($res);
        
    }
    
    /*
     * 获取单个项目的评论列表
     */
    public function get_one_comment() {
        $fid = I('get.fid');
    }
    
    /*
     * 获取单个项目的检验结果
     */
    public function get_one_report() {
        $fid = I('get.fid');
    }
    
    /*
     * 获取指定的众测的样品信息
     */
    public function get_one_samples() {
        $fdid = I("get.id");
        $finfo = M("fundings")->find($fdid);
        
        $sampleids = explode(",", $finfo['sampleid']);
        
        $sample_result = array();
        foreach ($sampleids as $key => $value) {
            $sample_result[]=  $this->get_sample_img_by_id($value);
        }
        
        $this->json_output($sample_result);
    }
    
    /*
     * 获取指定的众测的评论信息
     * 根据项目id 来获取评论
     * 
     */
    public function get_one_comments() {
        $fdid = I("get.id");
        $pid = I("get.pid");
        $pagecount = I("get.pagecount");
        
        if(empty($pagecount))
        {
            $pagecount=0;
        }
        
        $startcount = $pagecount*10;
        
        
        $DB = M("comments");
        
        $map['for_id']=$fdid;
        $map['ctype']=1;
        $map['pid']=$pid;
        $map['ishidden'] = 0;
        
        $res = $DB->where($map)->limit($startcount,10)->select();
        
        if(!empty($res))
        {
            foreach ($res as $key => $value) {
                /*
                * 获取单个用户的头像信息
                */
                $res[$key]['avatar']=  $this->_get_one_avatar($value['mid']);
                $res[$key]['username']=  $this->_get_member_nickname($value['mid']);
            }
            $this->json_output($res);
        }
        else
        {
            $result="";
            $this->json_output($result);
        }
        
    }
    
    /*
     * 针对项目进行评论
     */
    public function add_one_comment() {
        $mid = I('get.mid');
        $password = I('get.password');
        
        $chk_user = $this->chk_user($mid, $password);
        
        if($chk_user)
        {
            $fdid = I("get.id");
            $pid = I("get.pid");
            $content = I("get.content");


            $data['pid']=$pid;
            $data['mid']=$mid;
            $data['content']=$content;
            $data['ctype']=1;
            $data['for_id']=$fdid;
            $data['ctime']=I("server.REQUEST_TIME");
            $data['ishidden']=0;
            
            $DB = M("comments");
            
            $id = $DB->add($data);
//            print_r($DB->getLastSql());
            
            if($id)
            {
                if($pid>0)
                {
                    //对子评论进行评论
//                    需要增加父评论id 的评论数量
                    $DB_comment = M("comments");
                    $DB_comment->where("id=".$pid)->setInc("comment_count");
                    
                    
                    
                }
                /*
                    * 增加用户的健康豆
                    */
                   $this->member_action_bonus('comment', $mid, 1);
                $this->json_output($id);
        }
        else
        {
            $res['err']=1;
            $res['msg']="用户登录账户或密码有误".ACTION_NAME;
            echo json_encode($res);
        }
        
    }
    
    }
    
    /*
     * 增加评论的点赞
     */
    
    public function add_one_comment_like() {
        $mid = I('get.mid');
        $password = I('get.password');
        
        $chk_user = $this->chk_user($mid, $password);
        
        if($chk_user)
        {
            $cid = I("get.cid");


            $data['cid']=$cid;
            $data['mid']=$mid;
            $data['ctime']=I("server.REQUEST_TIME");
            
            $DB = M("comment_likes");
            
            $id = $DB->add($data);
            
            if($id)
            {
                $DB_comment = M("comments");
                $DB_comment->where("id=".$cid)->setInc("likecount");
//                print_r($DB_comment->getLastSql());
                
                $this->json_output($id);
            }
        }
        else
        {
            $res['err']=1;
            $res['msg']="用户登录账户或密码有误".ACTION_NAME;
            echo json_encode($res);
        }
    }
    
    /*
     * 针对项目的收藏功能
     */
    
    public function add_one_collection() {
       /*
        * 收藏or 取消收藏
        * 0 取消收藏
        * 1 收藏
        * 
        * ctype 2 资讯，1 项目
        */
        $mid = I('get.mid');
        $password = I('get.password');
        
        $chk_user = $this->chk_user($mid, $password);
        
        if($chk_user)
        {
            $ctype = 1;
            $forid = I("get.id");
            
            $ifcollection = I("get.ifcollection");
            
            $DB = M("collections");
       
            if($ifcollection==0)
            {
                $map['ctype']=$ctype;
                $map['for_id']=$forid;
                $map['mid']=$mid;

                $DB->where($map)->delete();
                
                $count = $DB->where(array('mid' => $mid,'ctype' => 1))->count();

                $this->json_output($count);
            }
            else
            {
                //新增
                $data['ctype']=$ctype;
                $data['for_id']=$forid;
                $data['mid']=$mid;
                $data['ctime']=I("server.REQUEST_TIME");


                $id =$DB->add($data,array(),true);
                if($id)
                {
                    $this->json_output($id);
                }

            }
           
        }
        else
        {
            $res['err']=1;
            $res['msg']="用户登录账户或密码有误".ACTION_NAME;
            echo json_encode($res);
        }
        
        
       
   }
   
   /*
    * 判断当前用户是否关注了该项目
    */
   private function chk_if_member_follow_founding($mid,$fdid) {
       $map['ctype']=1;
       $map['for_id']=$fdid;
       $map['mid']=$mid;
       
       $DB = M("collections");
       
       $res = $DB->where($map)->find();
       
       if(!empty($res))
       {
           return 1;
           
       }
       else
       {
           return 0;
       }
   }


   /*
     * 获取项目的点赞数量
     * 
     */
    
//    private function get_one_comment_like($cid) {
//        
//    }


    /*
     * 众筹项目的发起功能
     * POST
     * 
     */
    public function publish() {
        //检查提交的数据
//        $pjname=I('post.pjname');
        $pjname=I('post.pdname')."检测";
        if(!empty($pjname)){
                $data['pjname']=$pjname;
        }else{
                $res['err']=1;
                $res['msg']="数据不能为空1";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }


        $pdname=I('post.pdname');
        if(!empty($pdname)){
                $data['pdname']=$pdname;
        }else{
            $res['err']=1;
                $res['msg']="数据不能为空2";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }

        $brand=I('post.brand');
        if(!empty($brand)){
                $data['brand']=$brand;
        }else{
//            $res['err']=1;
//                $res['msg']="数据不能为空3";
//                $res['content']=  $_POST;
//                echo json_encode($res);
//                exit();
        }
        
        $batch=I('post.batch');
        if(!empty($batch)){
                $data['batch']=$batch;
        }else{

        }
        
        $member_upload_imgs = I("post.sampleid");
        if(!empty($member_upload_imgs)){
                $data['member_upload_imgs']=$member_upload_imgs;
        }else{

        }
        
        $category=I('post.categoryid');
        if(!empty($category)){
                $data['first_categoryid']=$category;
        }else{
            $res['err']=1;
                $res['msg']="错误8，产品分类数据不能为空";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }

        $package=I('post.packageid');
        if(!empty($package)){
                $data['packageid']=$package;
        }else{
            $res['err']=1;
                $res['msg']="数据不能为空4";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }


        $institution=I('post.institutionid');
        if(!empty($institution)){
                $data['institutionid']=$institution;
        }else{
            $res['err']=1;
                $res['msg']="数据不能为空5";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }


        $emoney=I('post.emoney');
        if(!empty($emoney)){
                $data['emoney']=$emoney;
        }else{
            $res['err']=1;
                $res['msg']="数据不能为空6";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }
        
        /*
         * 备注内容
         */
        $content = I('post.content');
        $data['content']=$content;
        

        $mid=I('post.mid');
        if(!empty($mid)){
                $data['mid']=$mid;
        }else{
            $res['err']=1;
                $res['msg']="数据不能为空7";
                $res['content']=  $_POST;
                echo json_encode($res);
                exit();
        }
            
        $citycode = I('post.citycode');
        //获取citycode 对应的城市地址
        $data['citycode']=$citycode;
        
        $cityname = $this->get_cityname_by_citycode($citycode);
        $data['location'] = $cityname.I("post.address");


//        $data['sampleid']=I('post.sampleid');
        $data['ctime']=I('server.REQUEST_TIME');
        $data['btime']=I('server.REQUEST_TIME');
        $data['rawdata'] = serialize($_POST);
        
        $data['member_upload_imgs']=I('post.sampleid');
        
        $DB = M('fundings');
        
        $id = $DB->add($data);
        if($id)
        {
            $this->json_output($id);
        }
        else
        {
            $this->json_output(0);
        }
        
        
    }
    
    
    /*
     * 提交图片
     */
    public function publish_image_upload() {
        if(IS_POST)
        {
            $img_url='/Uploads'.'/'.$this->upload($_FILES['image']);
            
            $DB = M("fundings_image");
            $data['img_url']=$img_url;
            
            $id = $DB->add($data);
//            echo $id;
            
            
            $this->json_output($id);
        }
        else
        {
            $this->display();
//            $this->json_output($id);
        }
        
    }
    
    public function publish_image_upload_result() {
        $id = trim(I('get.id'));
        
        $res = M("fundings_image")->find($id);
        
        $this->show("<img src='"."http://".I('server.HTTP_HOST')."/".$res['img_url']."' />");
    }
    
    
    
    /*
     * 众筹项目获取套餐功能
     * Date：2015-12-07 
     * 新增： 通过产品分类id来过滤
     */
    public function get_packages() {
        /*
         * 过滤项目对应的产品的分类
         * 前期木有，全场通用
         */
        $DB_sorts = M("classify_package_relationship");
        $sortid = I("get.sortid");
        if(!empty($sortid))
        {
            $map_sort['classify_id'] = $sortid;
            
        }
        
        $res_sort = $DB_sorts->where($map_sort)->select();
        
        $tmp_sortid = array();
        foreach ($res_sort as $k => $v) {
            $tmp_sortid[]=$v['package_id'];
        }
//        print_r($tmp_sortid);
        
        
        
        $DB = M('fundings_package');
//        $map
        $res = $DB->where($map)->select();
        
        
        
        
        
        foreach ($res as $key => $value) {
            //增加项目的名字
            $res[$key]['items'] = explode(',', $value['items']);
            $res[$key]['content'] = htmlspecialchars_decode($value['content']);
            $res[$key]['information'] = htmlspecialchars_decode($value['information']);
            /*
             * 判断是否是预选值
             */
            if(in_array($value['id'], $tmp_sortid))
            {
                $res[$key]['ischecked']=1;
                $test[$key]=1;
//                echo $value['id']."ok<br/>";
            }
            else
            {
               $res[$key]['ischecked']=0; 
               $test[$key]=0;
//               echo $value['id']."<br/>";
            }
            
        }
        arsort($test,SORT_NUMERIC);
        
        foreach ($test as $key => $value) {
            $new_res[]=$res[$key];
        }
        
        
        
        
        $test_items = M('test_items');
        foreach ($new_res as $k => $v) {
            foreach ($v['items'] as $key => $value) {
                $new_res[$k]['items'][$key] = $test_items->where(array('id' => $value))->getField('name');
            }
        }
        
        //将数组内容转化为字符串
        foreach ($new_res as $k => $v) {
            $new_res[$k]['itemsname']=implode('，',$v['items']);
        }
        
        $this->json_output($new_res);
    }
    
    /*
     * 众筹项目获取检测机构功能
     */
    public function get_labs() {
        /*
         * 过滤项目对应的产品的分类
         * 前期木有，全场通用
         */
        $DB = M('institution');
//        $map
        $res = $DB->where($map)->select();
        $this->json_output($res);
    }
    
    /*
     * 获取产品分类
     */
    public function get_sorts() {
        $DB = M("food_classify");
        $map['pid']=0;  //获取大类
        
        $res = $DB->where($map)->select();
//        $this->assign('sorts', $res);
        
        $this->json_output($res);
    }
    
      
    
    /*
     * 众筹项目的支付功能
     * @param fdid 众筹的id，amount 要支付的金额，分为单位，mid 支付的用户id，;
     * 
     * 
     * @date: 2016-01-23 
     * 增加红包的支付功能
     * 
     */
    public function payit() {
        $mid = I('get.mid');
        $password=I('get.password');
        $fdid = I('get.fdid');
        $type=I('get.type');
        $donatemoney = I('get.donate');
        $chk_usr = $this->chk_user($mid, $password);
        
        if($chk_usr)
        {
            $memberinfo = M("members")->find($mid);
            /*
             * 红包支付功能的判断
             */
            $rp_id = I("rp_id");
            if(!empty($rp_id))
            {
                $payment_discount  = $this->_cal_redpack($rp_id, $mid);
                
            }
            else
            {
                $payment_discount=0;
            }
            
            //计算扣除红包后的支付总费用
            $donatemoney = $donatemoney-$payment_discount;
            
//            print_r($payment_discount);
//            exit();
            
            
            
            
            
            
            if(!empty($type))
            {
                $founding_info = M('fundings')->find($fdid);
                
                /*
                 * 生成临时支付的订单
                 */
                
                
                //            零元支付的情况
                if($donatemoney==0||$donatemoney<0)
                {
                    $DB_sponsor = M('fundings_sponsor');
                    $data_sponsor['mid']=$mid;
                    $data_sponsor['paytype']=$type;
                    $data_sponsor['paytime']=I('server.REQUEST_TIME');
                    $data_sponsor['money']=$donatemoney;
                    $data_sponsor['fid']=$fdid;
                    $data_sponsor['status']=1;
                    $data_sponsor['type']=0;
                    $data_sponsor['rp_id']=$rp_id;

                    $sponsor_id = $DB_sponsor->add($data_sponsor);
                    
                    /*
                    * 更新这个记录到众筹的项目的总金额去
                    */
                    $this->_founding_finish_money_increase($fdid, $payment_discount);
//
                    /*
                     * 判断founding 是否满标，满的话，就改状态
                     */
                    $this->_chk_if_donate_ok($fdid);
//
                    /*
                    * 增加用户的健康豆
                    */
                    $this->member_action_bonus('payment', $mid, $payment_discount/100);
//
                    /*
                     * 更新用户使用的红包
                     */
                      
                    $this->_update_redpack_status($rp_id);
                      

                    $this->json_output($sponsor_id, "noneedpay", "err");
                    exit();
                }
                else
                {
                    $DB_sponsor = M('fundings_sponsor');
                    $data_sponsor['mid']=$mid;
                    $data_sponsor['paytype']=$type;
                    $data_sponsor['paytime']=I('server.REQUEST_TIME');
                    $data_sponsor['money']=$donatemoney;
                    $data_sponsor['fid']=$fdid;
                    $data_sponsor['status']=0;
                    $data_sponsor['type']=0;
                    $data_sponsor['rp_id']=$rp_id;

                    $sponsor_id = $DB_sponsor->add($data_sponsor);
                }
                
                /*
                * 判断订单是否过期
                */
//                $nowTimeStamp = I('server.REQUEST_TIME');
//                if($nowTimeStamp>$order_info['btime'])
//                {
//                    $res['err']=1;
//                    $res['msg']="订单已过期，请重新下订单";
//                    echo json_encode($res);
//                    exit();
//                }
            
                switch ($type) {
                    case 1:
                    //微信支付初始化
                        $app_Api = new \Com\WxPay\JsApi_pub();
                        $WxPayConf_pub = new \Com\WxPay\WxPayConf_pub();
                        //=========步骤2：使用统一支付接口，获取prepay_id============
                        //使用统一支付接口
                //        echo "3";
                        $unifiedOrder = new \Com\WxPay\UnifiedOrder_pub();
                //	echo $order['ordernum'];
                        //设置统一支付接口参数
                        //设置必填参数
                        //appid已填,商户无需重复填写
                        //mch_id已填,商户无需重复填写
                        //noncestr已填,商户无需重复填写
                        //spbill_create_ip已填,商户无需重复填写
                        //sign已填,商户无需重复填写
//                        $unifiedOrder->setParameter("openid","$openid");//商品描述
                        $body = $founding_info['pjname']."支付";
                        $unifiedOrder->setParameter("body",$body);//商品描述
                        //自定义订单号，此处仅作举例
                //	$timeStamp = I('server.REQUEST_TIME');
                //	$out_trade_no = WxPayConf_pub::APPID."$timeStamp";
                        $unifiedOrder->setParameter("out_trade_no",$sponsor_id."|".I('server.REQUEST_TIME'));//商户订单号 
//                        $unifiedOrder->setParameter("total_fee",$donatemoney);//总金额
//                        $unifiedOrder->setParameter("total_fee",$donatemoney);//总金额
                        if(!C('debug'))
                        {
//                            $unifiedOrder->setParameter("total_fee",1);//总金额
//                            $unifiedOrder->setParameter("total_fee",($donatemoney));//总金额
                            if($memberinfo['wxopenid']=="ozaQJv7aFKV0yIy4jybu9FqEo6XY")
                                {
                                    $unifiedOrder->setParameter("total_fee",1);//总金额
                                }
                                else
                                {
                    //                $unifiedOrder->setParameter("total_fee",1);//总金额
                                    $unifiedOrder->setParameter("total_fee",($donatemoney));//总金额
                                }
                        }
                        else
                        {
                            $unifiedOrder->setParameter("total_fee",1);//总金额
                        }
//                        $unifiedOrder->setParameter("total_fee",1);//总金额,测试1分钱
                        $unifiedOrder->setParameter("notify_url",$WxPayConf_pub::NOTIFY_URL_APP);//通知地址 
                        $unifiedOrder->setParameter("trade_type","APP");//交易类型
                        //非必填参数，商户可根据实际情况选填
                        //$unifiedOrder->setParameter("sub_mch_id","XXXX");//子商户号  
                        //$unifiedOrder->setParameter("device_info","XXXX");//设备号 
                        //$unifiedOrder->setParameter("attach","XXXX");//附加数据 
                        //$unifiedOrder->setParameter("time_start","XXXX");//交易起始时间
                        //$unifiedOrder->setParameter("time_expire","XXXX");//交易结束时间 
                        $unifiedOrder->setParameter("goods_tag",I('server.REQUEST_TIME'));//商品标记 
                        //$unifiedOrder->setParameter("openid","XXXX");//用户标识
                        $unifiedOrder->setParameter("product_id",$founding_info['id']);//商品ID
//                        print_r($unifiedOrder->createXml());
                        $prepay_id = $unifiedOrder->getPrepayId();
                        $data = $unifiedOrder->getParameters($prepay_id);
//                        echo json_encode($data);
                       
                        $this->json_output($data, "OK", "err");
//                        exit($prepay_id);
                        
                        //=========步骤3：使用jsapi调起支付============
//                        $app_Api->setPrepayId($prepay_id);
//
//                        $jsApiParameters = $app_Api->getParameters();
                        //echo $jsApiParameters;
//                        $this->json_output($jsApiParameters, 'OK', 'err');
//                        $this->assign('jsApiParameters', $jsApiParameters);

                        break;

                    default:
                        break;
                }
            }
            else
            {
                $res['err']=1;
                $res['msg']="订单支付方式有误";
                echo json_encode($res);
            }
   
        }
        else
        {
            $res['err']=1;
            $res['msg']="用户登录账户或密码有误".ACTION_NAME;
            echo json_encode($res);
        } 
    }
    
    
    /*
     * 计算红包的支付功能
     */
    public function _cal_redpack($rp_id,$mid) {
        $DB_redpack_create_records = M("redpack_create_records");
        
        $res_redpack_create_records = $DB_redpack_create_records->find($rp_id);
        if($res_redpack_create_records['isactived']==1)
        {
            $DB_redpack_receive_records = M("redpack_receive_records");
            $map['rp_id']=$rp_id;
            $map['mid']=$mid;
            
            $res_redpack_receive_records = $DB_redpack_receive_records->where($map)->find();
            
            if(!empty($res_redpack_receive_records))
            {
                if($res_redpack_receive_records['is_used']==0)
                {
//                    exit($res_redpack_create_records['cash']*100);
                    return $res_redpack_create_records['cash']*100;
                }
                else
                {
//                                exit("3");

                    return 0;
                }
            }
            else
            {
//                            exit("2");

                return 0;
            }
            
            
        }
        else
        {
//            exit("1");
            
            return 0;
        }
    }
    

    /*
     * 众筹项目的跟投赞助功能
     */
    public function sponsorit() {
        
    }
    
    /*
     * 获取分享链接
     * 
     * type 分享的类型，0 微信好友 1 微信朋友圈， 2  QQ， 3 微博
     */
    public function get_share() {
        $mid = I('get.mid');
        $fdid=I('get.fdid');
        
        $type=I("get.type");
        
        if(empty($type))
        {
            $type=1;
        }
        
        switch ($type) {
            case 1:  //微信
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['title']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['link']=$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');

                break;
                
            case 2:  //qq
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['title']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['link']=$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');

                break;
                
            case 3: // 微博
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧".$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');

                break;

            default: //默认
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['title']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['link']=$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');
                break;
        }
        
        
        
    }
    
    /*                           
     * 获取项目的分享（有红包）
     */
    public function get_share_with_redpack() {
        $mid = I('get.mid');
        $fdid=I('get.fdid');
        
        $type=I("get.type");
        
        if(empty($type))
        {
            $type=1;
        }
        
        $member_data = M("members")->find($mid);
        /*
         * 生成红包参数资料
         */
        $random_code = $this->_create_redpack_param($fdid, $member_data['wxopenid']);
        
        switch ($type) {
            case 1:  //微信
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['title']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['link']=$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid,'random_code'=>$random_code));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');

                break;
                
            case 2:  //qq
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['title']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['link']=$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');

                break;
                
            case 3: // 微博
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧".$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');

                break;

            default: //默认
                $fd_info = M('fundings')->find($fdid);
        
                //判断环境
                if(!C('debug'))
                {
                    $site_domain = C('product_domain');
                }
                else
                {
                    $site_domain = C('development_domain');
                }


                $share['title']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['desc']=$fd_info['pjname']."俺不想千毒不侵，集合爱吃的货货，凑份子钱测有没毒，快支持我一下吧";
                $share['link']=$site_domain.U('M/Founding/detail_of_share',array('fdid'=>$fdid,'random_code'=>$random_code));
                $share['imgUrl']=$site_domain."/Public/assets/img/logo.png";

                $this->json_output($share, '成功', '失败');
                break;
        }
        
        
        
    }
    
    /*
     * 分享成功后的健康豆获取
     */
    public function get_share_finish() {
        $mid = I('get.mid');
        $fdid=I('get.fdid');
        
        $this->member_action_bonus("forward", $mid, 1);
        
        $this->json_output($mid);
    }
    
    /*
     * 分享成功后的健康豆获取
     */
    public function get_promotion_finish() {
        $mid = I('get.mid');
        $fdid=I('get.fdid');
        
        $this->member_action_bonus("forward", $mid, 1);
        
        $this->json_output($fdid);
    }
    
    /*
     * 通过id获取获取机构的名称
     */
    private function get_institutionname_by_id($id) {
        $res = M('institution')->find($id);
        return $res['name'];
    }
    
    /*
     * 获取样品的绑定图片
     */
    private function get_sample_img_by_id($sampleid) {
        $DB = M("fundings_image");
        $res = $DB->find($sampleid);
        
        return $res;
    }


    /*
     * 通过id获取套餐信息
     */
    private function get_packagename_by_id($id) {
//        $res = M('fundings_package')->find($id);
//        return $res['name'];
        
        /*
         * 判断id 是单个还是多少
         */
        $id_arr = explode(',', $id);
        $DB = M('fundings_package');
        $name="";
        foreach ($id_arr as $key => $value) {
            $res[$key] = $DB->find($value);
            $name .=",".$res[$key]['name'];
//            echo $name;
        }

        return substr($name, 1);
    }
    
    /*
     * 通过id获取用户资料
     * 
     */
    private function get_username_by_id($mid) {
        $res = M('members')->find($mid);
        if(preg_match("/1[3458]{1}\d{9}$/",$res['username']))
        {
            $username = substr($res['username'], 0, -4)."****";
        }
        else
        {
            $username=$res['username'];
        }
        return $username;
    }

    
    /**
     date:   2015-10-10
     des:    检测套餐项目介绍相关知识接口
     */
    
    public function get_packages_information()
    {

        $id = I('get.id');
        $map['id'] = $id;

        $res = M('fundings_package')->field('name,content,information')->where($map)->find();

        if(!empty($res))
        {
            $res['err'] = 0;
            $res['msg'] = 'OK';
        }
        else
        {
            $res['err'] = 1;
            $res['msg'] = '获取数据失败';
        }
        echo json_encode($res);
    }
    
    /*
     * 获取检测报告
     */
    public function get_testreport_by_id($id) {
        $DB = M('testreport');
        $res = $DB->where(array('id' => $id))->field('id,download,download_jpg')->find();
        
        if(!empty($res)){

            return $res;
        }else{

            return $res = array();
        }
    }
    
    //文件上传累
    private function upload($file)
    {
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     5242880 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->savePath  =      'fundings/show/'; // 设置附件上传目录
            // 上传文件 
            $info   =   $upload->uploadOne($file);
            if(!$info)
            {
            // 上传错误提示错误信息    
                    $this->error($upload->getError());
            }
            else
            {
                    // 上传成功 获取上传文件信息    
                    return $info['savepath'].$info['savename'];    
            }
    }
    
    /*
     * 获取项目详情页面的最新的6个支持者
     * 按照金额排行
     * 
     */
    private function get_one_lastest_six_sponsors($fdid) {
        $map['status']=1;
        $map['fid']=$fdid;
        
        $DB = M("fundings_sponsor");
        
        $res = $DB->where($map)->order("money DESC")->limit(6)->select();
        
        if(!empty($res))
        {
            /*
            * 根据mid 获取到 头像等信息
            */
           foreach ($res as $key => $value) {
               /*
               * 获取单个用户的头像信息
               */
               $res[$key]['avatar']=  $this->_get_one_avatar($value['mid']);
               $res[$key]['username']=  $this->_get_member_nickname($value['mid']);
           }
        }
        else {
            $res = array();
        }
        
        
        return $res;
    }
    
    /*
     * 获取项目详情页面的支持者排行榜
     * 按照金额排行
     */
    private function get_one_most_sponsors($fdid) {
        $map['status']=1;
        $map['fid']=$fdid;
        
        $DB = M("fundings_sponsor");
        
        $res = $DB->where($map)->order("paytime DESC")->limit(10)->select();
        
        if(!empty($res))
        {
            /*
            * 根据mid 获取到 头像等信息
            */
           foreach ($res as $key => $value) {
               /*
               * 获取单个用户的头像信息
               */
               $res[$key]['avatar']=  $this->_get_one_avatar($value['mid']);
               $res[$key]['username']=  $this->_get_member_nickname($value['mid']);
           }
        }
        else
        {
            $res = array();
        }
        
        
        return $res;
    }
    
    /*
     * 获取项目详情页面的支持者排行榜
     * 按照金额排行
     */
    private function get_one_sponsor_count($fdid) {
        $map['status']=1;
        $map['fid']=$fdid;
        
        $DB = M("fundings_sponsor");
        
        $res = $DB->where($map)->count();
        
        
        return $res;
    }




    /*
     * 获取项目详情的精彩评论
     * 原型参考
     * http://test.mdjkj.com/mdjkj/ZC2.1.2/#p=a_1_3_2_项目详情_众测中_
     */
    private function get_one_hot_comments($fdid) {
//        有权重的方案
//        目前先按照评论数量来排序
        
        
        $map['for_id']=$fdid;
        $map['ctype']=1;
        $map['pid'] = 0;
        $map['ishidden'] = 0;
        $DB = M("comments");
        
        $res = $DB->where($map)->order("comment_count DESC")->limit(10)->select();
        if(!empty($res))
        {
            foreach ($res as $key => $value) {
                /*
                * 获取单个用户的头像信息
                */
                $res[$key]['avatar']=  $this->_get_one_avatar($value['mid']);
                $res[$key]['username']=  $this->_get_member_nickname($value['mid']);
            }
            
            return $res;
        }
        else{
            $result ="";
            return $result;
        }
    }
    
    /*
     * 获取项目的评论总数
     */
    private function get_one_comments_count($fdid) {
        $map['for_id']=$fdid;
        $map['ctype']=1;
        $map['pid']=  array('eq',0);
        $map['ishidden'] = 0;
        $DB = M("comments");
        
        $res = $DB->where($map)->count();
        if(!empty($res))
        {
            return $res;
        }
        else{
            return 0;
        }  
    }
    
    /*
     * 获取项目的图片展示列表
     * 
     * 
     * 
     * 临时要调整
     * 
     * 
     * 
     */
    private function get_one_thumb_list($detail_thumb_ids) {
//        $DB = M("fundings");
//        
//        $res = $DB->find($fdid);
//        
        $coverid = explode(",", $detail_thumb_ids);
        
        foreach($coverid as $key=>$value)
        {
            $thumb[] = M("fundings_image")->find($value);
        }
        
        if(!empty($thumb[0])){

            return $thumb;
        }else{

            return $thumb = array();
        }
        
        
        
    }


    /*
     * 获取单个用户的头像信息
     */
    private function _get_one_avatar($mid) {
        $member = $this->_get_member_info($mid);
        return $member['avatar'];
    }
    
    /*
     * 获取单个用户的昵称信息
     */
    private function _get_member_nickname($mid)
    {
        $member = $this->_get_member_info($mid);
        return $member['username'];
    }
    


    /*
     * 获取收藏资料
     * $return_type , 0 代表 是返回数字， 1代表返回数据
     */
    private function _get_member_collection($mid,$ctype,$return_type,$pagecount) {
        $map['ctype']=$ctype;
        $map['mid']=$mid;
        $pagecounts = $pagecount + 1;
        $res = M("collections")->where($map)->page($pagecounts,10)->order('ctime DESC')->group('for_id')->select();
        
        if($return_type==0)
        {
            return count($res);
        }
        else
        {
            if(!empty($res))
            {
                return $res;
            }
            else
            {
                return $res = array();
            }
        } 
    }



    /*
     * 计算项目要显示的图标
     */
     protected function _get_fouding_list_mark($type=0,$isqualified,$state) {
        switch ($state) {
            case 0:

//                return "img/verifying_mark.png";
                return "img/fouding_mark.png";
                break;
            case 1:
                return "img/fouding_mark.png";
                break;
            case 2:
                return "img/testing_mark.png";

                break;
            case 3:
                if($isqualified==1)
                {
                    return "img/qualified_mark.png";
                }
                else
                {
                    return "img/unqualified_mark.png";
                }
                break;
            case 4:
                return "img/cancel_mark.png";

                break;

            default:
                return "img/testing_mark.png";
                break;
        }
        
    }
   

    /**
     * 项目关注表
     */
    public function get_collection_foundings(){

        $mid = I('get.mid');
        $password = I('get.password');
        $pagecount = I('get.pagecount');
        $chk_user = $this->chk_user($mid, $password);
        if($chk_user){

            $ctype = 1;
            $return_type = 1;
            $list = $this->_get_member_collection($mid,$ctype,$return_type,$pagecount);

            /**
             * 循环获取关注项目的项目列表
             */
            $DB_f = M('fundings');
            $DB_t = M('testreport');
            foreach ($list as $key =>$value) {
                
                $flist[$key] =  $DB_f->find($value['for_id']);
                
                $list[$key]['thumb']=  ($flist[$key]['thumb']);
                $list[$key]['emoney']=  ($flist[$key]['emoney']+$flist[$key]['smoney']*$flist[$key]['samnum']);
                $list[$key]['finish']=  ($flist[$key]['finish']);
                $list[$key]['location']=  ($flist[$key]['location']);
                $list[$key]['packagename']=  $this->get_name_by_packageid($flist[$key]['packageid']);
                $list[$key]['pjname']=  ($flist[$key]['pjname']);
                $list[$key]['show_mark_icon']=  $this->_get_fouding_list_mark(0,$value['listult'],$value['state']);
                $list[$key]['rate'] = round($value['finish']*100/($value['emoney']+$value['smoney']*$value['samnum']),0);
                $list[$key]['result']=  ($flist[$key]['result']);
                $list[$key]['state']=  ($flist[$key]['state']);
                $list[$key]['batch']=  ($flist[$key]['batch']);
                $btime = $DB_t->where(array('id' => $flist[$key]['testreportid']))->getField('btime');
                $list[$key]['testing_date'] = date('Y-m-d',$btime);
            }
            if(!empty($list)){

                $res['err'] = 0;
                $res['msg'] = 'OK';
                $res['content'] = $list;
            }else{

                $res['err'] = 0;
                $res['msg'] = '没有数据!';
                $res['content'] = '';
            }

        }else{

            $res['err'] = 1;
            $res['msg'] = '用户信息验证失败!';
            $res['content'] = '';
        }

        echo json_encode($res); 
    }  
    
    /*
     * 生成红包参数记录
     */
    private function _create_redpack_param($fid,$openid) {
        $DB = M("redpack_create_param");
        
        $data['fid']=$fid;
        $data['openid']=$openid;
        $data['random_code']=  $this->_create_random_code(20);
        $data['ctime']=I("server.REQUEST_TIME");
        
        $id  = $DB->add($data);
        
        if($id)
        {
            return $data['random_code'];
        }
        else
        {
            return FALSE;
        }
    }
    
        /*
     * 生成随机码
     */
    private function _create_random_code($length)
    {
        $str = null;
        $strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
        $max = strlen($strPol)-1;

        for($i=0;$i<$length;$i++){
         $str.=$strPol[rand(0,$max)];//rand($min,$max)生成介于min和max两个数之间的一个随机整数
        }

        return $str;
    }
    
    
    /*
     * 获取项目的图片展示列表
     * 
     * 
     * 
     * 临时要调整
     * 
     * 
     * 
     */
//    private function get_one_thumb_list($detail_thumb_ids) {
////        $DB = M("fundings");
////        
////        $res = $DB->find($fdid);
////        
////        $thumb[]=$res['thumb'];
////        
////        
//        
//        $coverid = explode(",", $detail_thumb_ids);
//        
//        foreach($coverid as $key=>$value)
//        {
//            $thumb[] = M("fundings_image")->where('id='.$value)->getField('img_url');
//        }
////        print_r($detail_thumb_ids);
//        
//        return $thumb;
//        
//        
//    }
}
